#include "KeyboardController.h"
#include "Field.h"

bool KeyboardController::action( QKeyEvent* event ){
    /*if( event == 0 || lastUpdate == getMob()->getLastUpdate() ) return false;
    else lastUpdate = getMob()->getLastUpdate();*/
    if( event == 0 ) return false;
    Mob* m = getMob();
    int speed = m->getMoveSpeed();
    for( int i = 0; i < speed; i++ ){
        switch( event->key() ){
            case Qt::Key_A:
                m->getField()->move( WEST, 1, m );
                //m->paint();
                break;
            case Qt::Key_W:
                m->getField()->move( NORTH, 1, m );
                //m->paint();
                break;
            case Qt::Key_S:
                m->getField()->move( SOUTH, 1, m );
                //m->paint();
                break;
            case Qt::Key_D:
                m->getField()->move( EAST, 1, m );
                //m->paint();
                break;
            case Qt::Key_E:
                m->getField()->move( NORTHEAST, 1, m );
                //m->paint();
                break;
            case Qt::Key_C:
                m->getField()->move( SOUTHEAST, 1, m );
                //m->paint();
                break;
            case Qt::Key_Z:
                m->getField()->move( SOUTHWEST, 1, m );
                //m->paint();
                break;
            case Qt::Key_Q:
                m->getField()->move( NORTHWEST, 1, m );
                //m->paint();
                break;

            case Qt::Key_F:
                m->getField()->shift( m );
                //m->paint();
                return false;
                break;

            case Qt::Key_U:
                m->attack( NORTH );
                m->paint();
                return false;
                break;
            case Qt::Key_K:
                m->attack( EAST );
                m->paint();
                return false;
                break;
            case Qt::Key_H:
                m->attack( WEST );
                m->paint();
                return false;
                break;
            case Qt::Key_J:
                m->attack( SOUTH );
                m->paint();
                return false;
                break;
            case Qt::Key_Y:
                m->attack( NORTHWEST );
                m->paint();
                return false;
                break;
            case Qt::Key_I:
                m->attack( NORTHEAST );
                m->paint();
                return false;
                break;
            case Qt::Key_N:
                m->attack( SOUTHWEST );
                m->paint();
                return false;
                break;
            case Qt::Key_M:
                m->attack( SOUTHEAST );
                m->paint();
                return false;
                break;
            /*case Qt::Key_5:
                for( Direction i = NORTH; i < NONE; ++i ){
                    m->attack( i );
                }
                m->paint();
                return false;
                break;*/
            default: return false; break;
        }
    }
    m->paint();
    return false;
}
